package com.example.shortmessage.presenter;

import android.content.Context;

import com.example.shortmessage.contract.MessageContract;
import com.example.shortmessage.data.constant.MainConst;
import com.example.shortmessage.data.entity.MessageData;
import com.example.shortmessage.model.MessageModel;

import org.litepal.LitePal;

public class MessagePresenter extends MessageContract.Presenter<MessageContract.View> {

    private final MessageModel model;
    private Context context;

    public MessagePresenter(Context context) {
        model = new MessageModel();
        this.context=context;
    }

    @Override
    public void release() {

    }


    @Override
    public void upData(String id) {
        MessageData data = model.query(id);
        if(data==null) {
            mViewRef.get().onError(new Throwable(new RuntimeException("主键丢失")));
            return;
        }
        data.setRead(Integer.parseInt(MainConst.READ));
        data.update(data.getId());
    }

    @Override
    public void delete(MessageData data) {
        LitePal.delete(MessageData.class, data.getId());
    }
}
